Skip to content

test(utils): add extension-fallback UT for isMimeTypeSupport (PMS-383607) - #765

Merged
pengfeixx merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:atut-supplement/deepin-editor-20261201
Dec 2, 2026
Merged

pengfeixx merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:atut-supplement/deepin-editor-20261201

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Add 3 GTest cases for the extension-based MIME fallback branch (commit 0a0fdfe, PMS BUG-383607).

New tests:

  • IsMimeTypeSupport_PatchFile_ExtensionFallback_ReturnsTrue
  • IsMimeTypeSupport_BinaryUnknownExt_ExtensionDefaultGuarded_ReturnsFalse
  • IsMimeTypeSupport_PngFile_NonTextExtension_ReturnsFalse

All 8 isMimeTypeSupport tests pass (5 existing + 3 new), no regression.

PMS: BUG-383607

Summary by Sourcery

Tests:

  • Add three unit tests covering MIME-type extension fallback for patch files, unknown extensions, and non-text extensions.

…607)

Add 3 GTest cases covering the extension-based MIME fallback branch
introduced in commit 0a0fdfe:

- IsMimeTypeSupport_PatchFile_ExtensionFallback_ReturnsTrue: git
  format-patch .patch file content-detected as application/mbox falls
  back to extension (text/x-patch) and is accepted
- IsMimeTypeSupport_BinaryUnknownExt_ExtensionDefaultGuarded_ReturnsFalse:
  binary file with unknown extension (.zzz) rejected by isDefault() guard
- IsMimeTypeSupport_PngFile_NonTextExtension_ReturnsFalse: .png file with
  PNG content rejected — extension MIME is non-default but non-text and
  not in whitelist

PMS: BUG-383607
Log: 补充 isMimeTypeSupport 扩展名回退分支的单元测试
Influence: 仅新增测试用例,不改业务逻辑
@deepin-ci-robot

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@sourcery-ai

sourcery-ai Bot commented Dec 1, 2026

Copy link
Copy Markdown

Reviewer's Guide

Tests

Add three tests for extension-based MIME fallback outcomes and update the test inventory to reflect the eight covered scenarios.

  • tests/common/test_utils.cpp L76, L678-740

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@pengfeixx
pengfeixx marked this pull request as ready for review December 2, 2026 02:37
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, pengfeixx

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@pengfeixx
pengfeixx merged commit 8ae4965 into linuxdeepin:master Dec 2, 2026
19 of 20 checks passed
@pengfeixx
pengfeixx deleted the atut-supplement/deepin-editor-20261201 branch December 2, 2026 02:38

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/common/test_utils.cpp" line_range="708" />
<code_context>
+    const bool result = Utils::isMimeTypeSupport(path);
+
+    // Assert:扩展名回退 → text/x-patch(text/ 前缀)→ 放行
+    EXPECT_TRUE(result);
+}
+
</code_context>
<issue_to_address>
**Fallback regression goes unnoticed**

When the Qt MIME database classifies the patch fixture's content as a supported MIME type, `Utils::isMimeTypeSupport` returns true at the content-MIME check before reaching the extension fallback, so `EXPECT_TRUE(result)` passes even when that fallback is broken and the test reports the behavior as covered.

Use a fixture whose content MIME is unsupported so the assertion can pass only through the extension fallback.
</issue_to_address>

### Comment 2
<location path="tests/common/test_utils.cpp" line_range="708" />
<code_context>
+    const bool result = Utils::isMimeTypeSupport(path);
+
+    // Assert:扩展名回退 → text/x-patch(text/ 前缀)→ 放行
+    EXPECT_TRUE(result);
+}
+
</code_context>
<issue_to_address>
**Whitelist fallback remains untested**

When an extension resolves to a whitelisted MIME type that does not start with `text/`, a regression that removes the `SupportedTextMimeTypes` alternative still passes all eight MIME tests, leaving fallback for whitelisted non-`text/` extension MIME types broken.

Add a fallback test for an unsupported content MIME paired with a whitelisted, non-`text/` extension MIME type.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

const bool result = Utils::isMimeTypeSupport(path);

// Assert:扩展名回退 → text/x-patch(text/ 前缀)→ 放行
EXPECT_TRUE(result);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Fallback regression goes unnoticed

When the Qt MIME database classifies the patch fixture's content as a supported MIME type, Utils::isMimeTypeSupport returns true at the content-MIME check before reaching the extension fallback, so EXPECT_TRUE(result) passes even when that fallback is broken and the test reports the behavior as covered.

Use a fixture whose content MIME is unsupported so the assertion can pass only through the extension fallback.

Prompt for AI agents
In `tests/common/test_utils.cpp` at line 708:

**Fallback regression goes unnoticed**

When the Qt MIME database classifies the patch fixture's content as a supported MIME type, `Utils::isMimeTypeSupport` returns true at the content-MIME check before reaching the extension fallback, so `EXPECT_TRUE(result)` passes even when that fallback is broken and the test reports the behavior as covered.

Use a fixture whose content MIME is unsupported so the assertion can pass only through the extension fallback.

const bool result = Utils::isMimeTypeSupport(path);

// Assert:扩展名回退 → text/x-patch(text/ 前缀)→ 放行
EXPECT_TRUE(result);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Whitelist fallback remains untested

When an extension resolves to a whitelisted MIME type that does not start with text/, a regression that removes the SupportedTextMimeTypes alternative still passes all eight MIME tests, leaving fallback for whitelisted non-text/ extension MIME types broken.

Add a fallback test for an unsupported content MIME paired with a whitelisted, non-text/ extension MIME type.

Prompt for AI agents
In `tests/common/test_utils.cpp` at line 708:

**Whitelist fallback remains untested**

When an extension resolves to a whitelisted MIME type that does not start with `text/`, a regression that removes the `SupportedTextMimeTypes` alternative still passes all eight MIME tests, leaving fallback for whitelisted non-`text/` extension MIME types broken.

Add a fallback test for an unsupported content MIME paired with a whitelisted, non-`text/` extension MIME type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants